package router

import (
	"app/internal/middleware"
	"app/internal/services"
	apiCarousel "app/internal/services/api/carousel"
	"app/internal/services/express"
	"app/internal/services/location"

	"github.com/gin-gonic/gin"
)

func RegisterApiRouters(r *gin.Engine) {
	openapi := r.Group("api", middleware.SharedParamsMiddleware(), middleware.InitUserinfoMiddleware())
	noauthCommGroup := openapi.Group("common")
	{
		noauthCommGroup.POST("setting-get", services.SystemGet)
		noauthCommGroup.POST("file/upload", services.Upload)

	}
	//轮播图管理
	carousel := openapi.Group("carousel")
	{
		carousel.GET("list", apiCarousel.List) // 轮播图列表
	}

	//微信相关
	wx := openapi.Group("wx")
	wxauth := openapi.Group("wx", middleware.JwtMiddleware())
	{
		wx.POST("login", services.WxLogin)
		wx.POST("mocklog", services.MockLog)
		wx.GET("profile", services.Profile)
		wxauth.POST("bind-phone", services.WxBindPhone)
	}

	expressG := openapi.Group("express", middleware.JwtMiddleware())
	{
		expressG.POST("take-add", express.TakeAdd)
		expressG.POST("take-edit", express.TakeEdit)
		expressG.GET("takes", express.Takes)
	}

	userGroup := openapi.Group("user", middleware.JwtMiddleware())
	{
		userGroup.POST("edit", services.Edit)
		userGroup.POST("password", services.Editpassword)
		userGroup.GET("profile", services.Profile)
	}

	locationG := userGroup.Group("location")
	{
		locationG.POST("add", location.Add)
		locationG.POST("edit", location.Edit)
		locationG.POST("del", location.Del)
		locationG.GET("list", location.List)
		locationG.GET("info", location.Info)
	}

	//管理后台独有接口放这里面
	authManager := r.Group("manager", middleware.SharedParamsMiddleware(), middleware.JwtMiddleware())
	expressMG := authManager.Group("express", middleware.JwtMiddleware())
	{
		expressMG.GET("takes", express.ManagerTakes)
		expressMG.POST("take-edit", express.ManagerTakeEdit)
	}
	carouselManager := authManager.Group("carousel")
	{
		carouselManager.POST("add", apiCarousel.Add)         // 轮播图新增
		carouselManager.POST("edit", apiCarousel.Edit)       // 轮播图编辑
		carouselManager.GET("list", apiCarousel.ManagerList) // 轮播图列表
		carouselManager.POST("delete", apiCarousel.Delete)   // 轮播图删除
	}

	commGroup := authManager.Group("common")
	{
		commGroup.POST("file/upload", services.Upload)
		commGroup.POST("/send_sms", services.SendVerificationCode) // 发送验证码
	}

	//系统设置
	settingGroup := authManager.Group("setting")
	{
		settingGroup.POST("get", services.SettingGet)
		settingGroup.POST("set", services.SettingSet)
	}

}
